Setup instructions

Install the Anaconda Python distribution

If using your own computer please install the Anaconda Python distribution from https://www.anaconda.com/download/. (Note that Python version \(\leq\) 3.0 differs considerably from more recent releases. For this workshop you will need version \(\geq\) 3.4.)

Accepting the defaults proposed by the Anaconda installer is generally recommended.

Workshop notes

The class notes for this workshop are available on our website at dss.iq.harvard.edu under Workshop Materials ==> Python Workshop Materials => Python Web Scraping. Click the All workshop materials link to download the workshop materials.

Extract the PythonWebScraping.zip directory (Right-click => Extract All on Windows, double-click on Mac).

Start the Jupyter Notebook application and open the Exercises.ipynb file in the PythonWebScraping folder you downloaded previously. You may also wish to start a new notebook for your own notes.

Workshop goals and approach

In this workshop you will - learn basic web scraping principles and techniques, - learn how to use the requests package in Python, - practice making requests and manipulating responses from the server.

This workshop is relatively informal, example-oriented, and hands-on. We will learn by working through an example web scraping project.

Note that this is not an introductory workshop. Familiarity with Python, including but not limited to knowledge of lists and dictionaries, indexing, and loops and / or comprehensions is assumed. If you need an introduction to Python or a refresher, we recommend the IQSS Introduction to Python.

Note also that this workshop will not teach you everything you need to know in order to retrieve data from any web service you might wish to scrape. You can expect to learn just enough to be dangerous.

Preliminary questions

What is web scraping?

Web scraping is the activity of automating retrieval of information from a web service designed for human interaction.

Example project overview and goals

In this workshop I will demonstrate web scraping techniques using the Collections page at https://www.harvardartmuseums.org/collections and let you use the skills you’ll learn to retrieve information from other parts of the Harvard Art Museums website.

The basic strategy is pretty much the same for most scraping projects. We will use our web browser (Chrome or Firefox recommended) to examine the page you wish to retrieve data from, and copy/paste information from your web browser into your scraping program.

Take shortcuts if you can

We wish to extract information from https://www.harvardartmuseums.org/collections. Like most modern web pages, a lot goes on behind the scenes to produce the page we see in our browser. Our goal is to pull back the curtain to see what the website does when we interact with it. Once we see how the website works we can start retrieving data from it. If we are lucky we’ll find a resource that returns the data we’re looking for in a structured format like JSON or XML.

Examining the structure of our target web service

We start by opening the collections web page in a web browser and inspecting it.

If we scroll down to the bottom of the Collections page, we’ll see a button that says “Load More”. Let’s see what happens when we click on that button. To do so, click on “Network” in the developer tools window, then click the “Load More Collections” button. You should see a list of requests that were made as a result of clicking that button, as shown below.

If we look at that second request, the one to a script named browse, we’ll see that it returns all the information we need, in a convenient format called JSON. All we need to retrieve collection data is call make GET requests to https://www.harvardartmuseums.org/browse with the correct parameters.

Making requests using python

The URL we want to retrieve data from has the following structure

scheme                    domain    path  parameters
 https www.harvardartmuseums.org  browse  load_amount=10&offset=0

It is often convenient to create variables containing the domain(s) and path(s) you’ll be working with, as this allows you to swap out paths and parameters as needed. Note that the path is separated from the domain with / and the parameters are separated from the path with ?. If there are multiple parameters they are separated from each other with a &.

For example, we can define the domain and path of the collections URL as follows:

## 'https://www.harvardartmuseums.org/browse'

Note that we omit the parameters here because it is usually easier to pass them as a dict when using the requests library in Python. This will become clearer shortly.

Now that we’ve constructed the URL we wish interact with we’re ready to make our first request in Python.

Parsing JSON data

We already know from inspecting network traffic in our web browser that this URL returns JSON, but we can use Python to verify this assumption.

Since JSON is a structured data format, parsing it into python data structures is easy. In fact, there’s a method for that!

## {'info': {'next': 'https://api.harvardartmuseums.org/object?apikey=67d9edc0-e6a3-11e3-9798-57275476509a&sort=rank&sortorder=asc&from=0&size=10&page=2',
##           'page': 1,
##           'pages': 23295,
##           'totalrecords': 232947,
##           'totalrecordsperquery': 10},
##  'records': [{'accessionmethod': 'Gift',
##               'accessionyear': 1927,
##               'accesslevel': 1,
##               'century': '5th century BCE',
##               'classification': 'Vessels',
##               'classificationid': 57,
##               'colorcount': 10,
##               'colors': [{'color': '#191919',
##                           'css3': '#000000',
##                           'hue': 'Grey',
##                           'percent': 0.21784946236559,
##                           'spectrum': '#1eb264'},
##                          {'color': '#e1e1e1',
##                           'css3': '#dcdcdc',
##                           'hue': 'Grey',
##                           'percent': 0.15483870967742,
##                           'spectrum': '#955ba5'},
##                          {'color': '#969696',
##                           'css3': '#a9a9a9',
##                           'hue': 'Grey',
##                           'percent': 0.12408602150538,
##                           'spectrum': '#8761aa'},
##                          {'color': '#afafaf',
##                           'css3': '#a9a9a9',
##                           'hue': 'Grey',
##                           'percent': 0.11774193548387,
##                           'spectrum': '#8c5fa8'},
##                          {'color': '#4b4b4b',
##                           'css3': '#2f4f4f',
##                           'hue': 'Grey',
##                           'percent': 0.097741935483871,
##                           'spectrum': '#3db657'},
##                          {'color': '#323232',
##                           'css3': '#2f4f4f',
##                           'hue': 'Grey',
##                           'percent': 0.092204301075269,
##                           'spectrum': '#2eb45d'},
##                          {'color': '#c8c8c8',
##                           'css3': '#c0c0c0',
##                           'hue': 'Grey',
##                           'percent': 0.082956989247312,
##                           'spectrum': '#8c5fa8'},
##                          {'color': '#7d7d7d',
##                           'css3': '#808080',
##                           'hue': 'Grey',
##                           'percent': 0.043978494623656,
##                           'spectrum': '#8362aa'},
##                          {'color': '#966432',
##                           'css3': '#a0522d',
##                           'hue': 'Orange',
##                           'percent': 0.023064516129032,
##                           'spectrum': '#e46867'},
##                          {'color': '#af644b',
##                           'css3': '#cd5c5c',
##                           'hue': 'Orange',
##                           'percent': 0.01752688172043,
##                           'spectrum': '#e0626d'}],
##               'commentary': None,
##               'contact': 'am_asianmediterranean@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': None,
##               'creditline': 'Harvard Art Museums/Arthur M. Sackler Museum, '
##                             'Gift of E. P. Warren, Esquire',
##               'culture': 'Greek',
##               'datebegin': -480,
##               'dated': '480-470 BCE',
##               'dateend': -470,
##               'dateoffirstpageview': '2009-09-17',
##               'dateoflastpageview': '2018-10-11',
##               'department': 'Department of Ancient and Byzantine Art & '
##                             'Numismatics',
##               'description': None,
##               'dimensions': 'with handles: 8.8 x 25.6 x 19 cm (3 7/16 x 10 '
##                             '1/16 x 7 1/2 in.)',
##               'division': 'Asian and Mediterranean Art',
##               'edition': None,
##               'exhibitioncount': 4,
##               'groupcount': 2,
##               'id': 287256,
##               'imagecount': 2,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/17388790',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 2124,
##                           'idsid': 17388790,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/17388790',
##                           'imageid': 17459,
##                           'publiccaption': None,
##                           'renditionnumber': '53731',
##                           'width': 2550},
##                          {'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/17388792',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 2,
##                           'format': 'image/jpeg',
##                           'height': 2121,
##                           'idsid': 17388792,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/17388792',
##                           'imageid': 131594,
##                           'publiccaption': 'side view',
##                           'renditionnumber': '53733',
##                           'width': 2550}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:16:28-0500',
##               'markscount': 0,
##               'mediacount': 0,
##               'medium': 'Terracotta',
##               'objectid': 287256,
##               'objectnumber': '1927.155',
##               'people': [{'alphasort': 'Akestorides Painter',
##                           'birthplace': None,
##                           'culture': 'Greek',
##                           'deathplace': None,
##                           'displaydate': 'active ca. 475 -450 BCE',
##                           'displayname': 'Manner of The Akestorides Painter',
##                           'displayorder': 1,
##                           'gender': 'unknown',
##                           'name': 'The Akestorides Painter',
##                           'personid': 35316,
##                           'prefix': 'Manner of',
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': 'Classical period, Early',
##               'periodid': 906,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/17388790',
##               'provenance': 'Edward Perry Warren, Esq., London, (by '
##                             '1927-1928), gift; to Fogg Art Museum, 1927.',
##               'publicationcount': 3,
##               'rank': 1,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/287256',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': None,
##               'standardreferencenumber': 'Beazley Archive Database #209939',
##               'state': None,
##               'style': 'Red-figure',
##               'technique': 'Red-figure',
##               'techniqueid': 7317,
##               'title': 'Kylix (drinking cup): Woman Pouring a Libation at an '
##                        'Altar',
##               'titlescount': 1,
##               'totalpageviews': 714,
##               'totaluniquepageviews': 600,
##               'url': 'https://www.harvardartmuseums.org/collections/object/287256',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'vessel', 'worktypeid': '389'}]},
##              {'accessionmethod': 'Purchase',
##               'accessionyear': 2007,
##               'accesslevel': 1,
##               'century': '20th-21st century',
##               'classification': 'Photographs',
##               'classificationid': 17,
##               'colorcount': 0,
##               'commentary': None,
##               'contact': 'am_moderncontemporary@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': '© Vik Muniz / Licensed by VAGA, New York, NY',
##               'creditline': 'Harvard Art Museums/Fogg Museum, Margaret Fisher '
##                             'Fund',
##               'culture': 'Brazilian',
##               'datebegin': 2002,
##               'dated': '2002',
##               'dateend': 2002,
##               'dateoffirstpageview': '2009-06-23',
##               'dateoflastpageview': '2018-10-13',
##               'department': 'Department of Photographs',
##               'description': 'Piece consists of eight prints.',
##               'dimensions': 'sheet: 48.2 x 55.9 cm (19 x 22 in.)',
##               'division': 'Modern and Contemporary Art',
##               'edition': '14/40',
##               'exhibitioncount': 1,
##               'groupcount': 1,
##               'id': 322324,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/20380023',
##                           'copyright': None,
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 2217,
##                           'idsid': 20380023,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/20380023',
##                           'imageid': 265476,
##                           'publiccaption': None,
##                           'renditionnumber': 'DDC103850',
##                           'width': 2550}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:22:37-0500',
##               'markscount': 2,
##               'mediacount': 0,
##               'medium': 'Iris prints with silkscreen varnish',
##               'objectid': 322324,
##               'objectnumber': '2007.182.6',
##               'people': [{'alphasort': 'Muniz, Vik',
##                           'birthplace': 'São Paulo, Brazil',
##                           'culture': 'American',
##                           'deathplace': None,
##                           'displaydate': 'born 1961',
##                           'displayname': 'Vik Muniz',
##                           'displayorder': 1,
##                           'gender': 'male',
##                           'name': 'Vik Muniz',
##                           'personid': 52534,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/20380023',
##               'provenance': None,
##               'publicationcount': 0,
##               'rank': 2,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/322324',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': 'verso, b.r. in graphite: Vik Muniz 2002',
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': 'Iris digital print',
##               'techniqueid': 2452,
##               'title': 'After Motherwell',
##               'titlescount': 2,
##               'totalpageviews': 582,
##               'totaluniquepageviews': 474,
##               'url': 'https://www.harvardartmuseums.org/collections/object/322324',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'photograph', 'worktypeid': '259'}]},
##              {'accessionmethod': 'Purchase',
##               'accessionyear': 2007,
##               'accesslevel': 1,
##               'century': '20th century',
##               'classification': 'Drawings',
##               'classificationid': 21,
##               'colorcount': 0,
##               'commentary': None,
##               'contact': 'am_moderncontemporary@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': '© Jess - The Jess Collins Trust',
##               'creditline': 'Harvard Art Museums/Fogg Museum, Margaret Fisher '
##                             'Fund',
##               'culture': 'American',
##               'datebegin': 1955,
##               'dated': '1955',
##               'dateend': 0,
##               'dateoffirstpageview': '2009-08-06',
##               'dateoflastpageview': '2018-10-14',
##               'department': 'Department of Drawings',
##               'description': None,
##               'dimensions': 'including mount: 51 x 40.7 cm (20 1/16 x 16 '
##                             'in.)\r\n'
##                             'collage: 42 x 34.5 cm (16 9/16 x 13 9/16 in.)',
##               'division': 'Modern and Contemporary Art',
##               'edition': None,
##               'exhibitioncount': 4,
##               'groupcount': 1,
##               'id': 317744,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/18773215',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 2550,
##                           'idsid': 18773215,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/18773215',
##                           'imageid': 231591,
##                           'publiccaption': None,
##                           'renditionnumber': 'DDC101611',
##                           'width': 2035}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:21:59-0500',
##               'markscount': 1,
##               'mediacount': 0,
##               'medium': 'Paper collage ("paste-up"), mounted on brown paper',
##               'objectid': 317744,
##               'objectnumber': '2007.27',
##               'people': [{'alphasort': 'Jess',
##                           'birthplace': 'Long Beach, CA',
##                           'culture': 'American',
##                           'deathplace': 'San Francisco, CA',
##                           'displaydate': '1923 - 2004',
##                           'displayname': 'Jess',
##                           'displayorder': 1,
##                           'gender': 'unknown',
##                           'name': 'Jess',
##                           'personid': 51752,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/18773215',
##               'provenance': None,
##               'publicationcount': 4,
##               'rank': 3,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/317744',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': "mount, l.r., graphite: Jess / '55",
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': 'Collage',
##               'techniqueid': 430,
##               'title': 'A Paranoic Portrait of Robert Creeley',
##               'titlescount': 1,
##               'totalpageviews': 500,
##               'totaluniquepageviews': 433,
##               'url': 'https://www.harvardartmuseums.org/collections/object/317744',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'drawing', 'worktypeid': '125'}]},
##              {'accessionmethod': 'Purchase',
##               'accessionyear': 2008,
##               'accesslevel': 1,
##               'century': '20th century',
##               'classification': 'Photographs',
##               'classificationid': 17,
##               'colorcount': 0,
##               'commentary': None,
##               'contact': 'am_moderncontemporary@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': None,
##               'creditline': 'Harvard Art Museums/Fogg Museum, Richard and '
##                             'Ronay Menschel Fund for the Acquisition of '
##                             'Photographs',
##               'culture': 'American',
##               'datebegin': 1951,
##               'dated': '1951',
##               'dateend': 1951,
##               'dateoffirstpageview': '2009-05-12',
##               'dateoflastpageview': '2018-10-14',
##               'department': 'Department of Photographs',
##               'description': None,
##               'dimensions': 'image: 22.2 x 34 cm (8 3/4 x 13 3/8 in.)\r\n'
##                             'sheet: 27.5 x 35.5 cm (10 13/16 x 14 in.)',
##               'division': 'Modern and Contemporary Art',
##               'edition': None,
##               'exhibitioncount': 0,
##               'groupcount': 2,
##               'id': 320567,
##               'imagecount': 2,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/10466656',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 1667,
##                           'idsid': 10466656,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/10466656',
##                           'imageid': 320875,
##                           'publiccaption': None,
##                           'renditionnumber': 'DDC105926',
##                           'width': 2550},
##                          {'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/20434940',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 2,
##                           'format': 'image/jpeg',
##                           'height': 1662,
##                           'idsid': 20434940,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/20434940',
##                           'imageid': 292285,
##                           'publiccaption': None,
##                           'renditionnumber': 'INV177643',
##                           'width': 2550}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:22:23-0500',
##               'markscount': 1,
##               'mediacount': 0,
##               'medium': None,
##               'objectid': 320567,
##               'objectnumber': '2008.20',
##               'people': [{'alphasort': 'Callahan, Harry N.',
##                           'birthplace': 'Detroit, Michigan',
##                           'culture': 'American',
##                           'deathplace': None,
##                           'displaydate': '1912 - 1999',
##                           'displayname': 'Harry Callahan',
##                           'displayorder': 1,
##                           'gender': 'male',
##                           'name': 'Harry Callahan',
##                           'personid': 34536,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/10466656',
##               'provenance': None,
##               'publicationcount': 0,
##               'rank': 4,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/320567',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': 'recto, b.r. corner, in graphite:  Harry Callahan',
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': 'Dye transfer print',
##               'techniqueid': 1615,
##               'title': 'Detroit (Ragsdale Beauty Shop)',
##               'titlescount': 1,
##               'totalpageviews': 667,
##               'totaluniquepageviews': 534,
##               'url': 'https://www.harvardartmuseums.org/collections/object/320567',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'photograph', 'worktypeid': '259'}]},
##              {'accessionmethod': 'Purchase',
##               'accessionyear': 2008,
##               'accesslevel': 1,
##               'century': '20th century',
##               'classification': 'Photographs',
##               'classificationid': 17,
##               'colorcount': 0,
##               'commentary': None,
##               'contact': 'am_moderncontemporary@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': '© Artists Rights Society (ARS), New York / VG '
##                            'Bild-Kunst, Germany',
##               'creditline': 'Harvard Art Museums/Busch-Reisinger Museum, '
##                             'Purchase through the generosity of Richard and '
##                             'Priscilla Hunt',
##               'culture': 'German',
##               'datebegin': 1934,
##               'dated': '1934-1935?',
##               'dateend': 1935,
##               'dateoffirstpageview': '2009-06-15',
##               'dateoflastpageview': '2018-10-16',
##               'department': 'Busch-Reisinger Museum',
##               'description': None,
##               'dimensions': '23 x 17.1 cm (9 1/16 x 6 3/4 in.)',
##               'division': 'Modern and Contemporary Art',
##               'edition': None,
##               'exhibitioncount': 0,
##               'groupcount': 1,
##               'id': 324662,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/10466657',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 2550,
##                           'idsid': 10466657,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/10466657',
##                           'imageid': 320876,
##                           'publiccaption': None,
##                           'renditionnumber': 'DDC105927',
##                           'width': 1910}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:23:02-0500',
##               'markscount': 5,
##               'mediacount': 0,
##               'medium': None,
##               'objectid': 324662,
##               'objectnumber': '2008.29',
##               'people': [{'alphasort': 'Renger-Patzsch, Albert',
##                           'birthplace': 'Würzburg',
##                           'culture': 'German',
##                           'deathplace': 'Wamel bei Soest',
##                           'displaydate': '1897 - 1966',
##                           'displayname': 'Albert Renger-Patzsch',
##                           'displayorder': 1,
##                           'gender': 'male',
##                           'name': 'Albert Renger-Patzsch',
##                           'personid': 28243,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/10466657',
##               'provenance': 'Albert Renger-Patzsch, Essen, created, '
##                             '1934-35?\r\n'
##                             "Christie's, New York, sold, April 24, 2007, no. "
##                             '308\r\n'
##                             'Charles Isaacs Photographs, Inc., New York, '
##                             "purchased at Christie's, New York, April 24, "
##                             '2007, sold to Busch-Reisinger Museum, 2008.',
##               'publicationcount': 0,
##               'rank': 5,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/324662',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': None,
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': 'Gelatin silver print',
##               'techniqueid': 123,
##               'title': '[Detail of a Benzene Wash, Scholven Coal Mine near '
##                        'Buer]',
##               'titlescount': 1,
##               'totalpageviews': 429,
##               'totaluniquepageviews': 382,
##               'url': 'https://www.harvardartmuseums.org/collections/object/324662',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'photograph', 'worktypeid': '259'}]},
##              {'accessionmethod': 'Transfer',
##               'accessionyear': 2011,
##               'accesslevel': 1,
##               'century': '19th century',
##               'classification': 'Photographs',
##               'classificationid': 17,
##               'colorcount': 0,
##               'commentary': None,
##               'contact': 'am_europeanamerican@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': None,
##               'creditline': 'Harvard Art Museums/Fogg Museum, Transfer from '
##                             'the Carpenter Center for the Visual Arts, '
##                             'Transferred from the Geology Library',
##               'culture': 'American',
##               'datebegin': 1865,
##               'dated': 'c. 1870',
##               'dateend': 1875,
##               'dateoffirstpageview': '2009-08-02',
##               'dateoflastpageview': '2018-10-16',
##               'department': 'Department of Photographs',
##               'description': None,
##               'dimensions': 'image: 33 x 25 cm (13 x 9 13/16 in.)\r\n'
##                             'mount: 50.5 x 40.5 cm (19 7/8 x 15 15/16 in.)',
##               'division': 'European and American Art',
##               'edition': None,
##               'exhibitioncount': 1,
##               'groupcount': 1,
##               'id': 158904,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/18792728',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 2550,
##                           'idsid': 18792728,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/18792728',
##                           'imageid': 116541,
##                           'publiccaption': None,
##                           'renditionnumber': 'INV027402',
##                           'width': 1927}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T03:52:54-0500',
##               'markscount': 0,
##               'mediacount': 0,
##               'medium': None,
##               'objectid': 158904,
##               'objectnumber': '2.2002.385',
##               'people': [{'alphasort': 'Hillers, John K.',
##                           'birthplace': 'Hanover, Germany',
##                           'culture': 'American',
##                           'deathplace': 'Washington, D.C.',
##                           'displaydate': 'c. 1843 - c. 1925',
##                           'displayname': 'John K. Hillers',
##                           'displayorder': 1,
##                           'gender': 'male',
##                           'name': 'John K. Hillers',
##                           'personid': 22090,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/18792728',
##               'provenance': None,
##               'publicationcount': 0,
##               'rank': 6,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/158904',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': None,
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': 'Albumen silver print',
##               'techniqueid': 110,
##               'title': 'The Captain of the Rio Virgen, Utah',
##               'titlescount': 1,
##               'totalpageviews': 480,
##               'totaluniquepageviews': 427,
##               'url': 'https://www.harvardartmuseums.org/collections/object/158904',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'photograph', 'worktypeid': '259'}]},
##              {'accessionmethod': 'Gift',
##               'accessionyear': 1933,
##               'accesslevel': 1,
##               'century': '18th century',
##               'classification': 'Prints',
##               'classificationid': 23,
##               'colorcount': 10,
##               'colors': [{'color': '#4b4b4b',
##                           'css3': '#2f4f4f',
##                           'hue': 'Grey',
##                           'percent': 0.46435643564356,
##                           'spectrum': '#3db657'},
##                          {'color': '#e1c8af',
##                           'css3': '#f5deb3',
##                           'hue': 'Orange',
##                           'percent': 0.22310231023102,
##                           'spectrum': '#e9715f'},
##                          {'color': '#191919',
##                           'css3': '#000000',
##                           'hue': 'Grey',
##                           'percent': 0.078349834983498,
##                           'spectrum': '#1eb264'},
##                          {'color': '#323232',
##                           'css3': '#2f4f4f',
##                           'hue': 'Grey',
##                           'percent': 0.062772277227723,
##                           'spectrum': '#2eb45d'},
##                          {'color': '#7d644b',
##                           'css3': '#696969',
##                           'hue': 'Yellow',
##                           'percent': 0.053663366336634,
##                           'spectrum': '#b25593'},
##                          {'color': '#c8af96',
##                           'css3': '#d2b48c',
##                           'hue': 'Brown',
##                           'percent': 0.046798679867987,
##                           'spectrum': '#e66c64'},
##                          {'color': '#96967d',
##                           'css3': '#808080',
##                           'hue': 'Green',
##                           'percent': 0.037095709570957,
##                           'spectrum': '#8e5ea7'},
##                          {'color': '#e1e1c8',
##                           'css3': '#dcdcdc',
##                           'hue': 'Green',
##                           'percent': 0.015973597359736,
##                           'spectrum': '#e9715f'},
##                          {'color': '#fae1e1',
##                           'css3': '#ffe4e1',
##                           'hue': 'Red',
##                           'percent': 0.012013201320132,
##                           'spectrum': '#e76d63'},
##                          {'color': '#c8af64',
##                           'css3': '#bdb76b',
##                           'hue': 'Yellow',
##                           'percent': 0.0048844884488449,
##                           'spectrum': '#b0d136'}],
##               'commentary': None,
##               'contact': 'am_asianmediterranean@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': None,
##               'creditline': 'Harvard Art Museums/Arthur M. Sackler Museum, '
##                             'Gift of the Friends of Arthur B. Duel',
##               'culture': 'Japanese',
##               'datebegin': 1794,
##               'dated': 'Late Edo period, 1794 (5th month)',
##               'dateend': 1794,
##               'dateoffirstpageview': '2009-06-30',
##               'dateoflastpageview': '2018-10-16',
##               'department': 'Department of Asian Art',
##               'description': None,
##               'dimensions': 'Vertical ôban: H. 37.7 cm x W. 25.4 cm (14 13/16 '
##                             'x 10 in.)',
##               'division': 'Asian and Mediterranean Art',
##               'edition': None,
##               'exhibitioncount': 1,
##               'groupcount': 2,
##               'id': 207197,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/17388061',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 2550,
##                           'idsid': 17388061,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/17388061',
##                           'imageid': 20571,
##                           'publiccaption': None,
##                           'renditionnumber': '52247',
##                           'width': 1731}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:00:56-0500',
##               'markscount': 1,
##               'mediacount': 0,
##               'medium': 'Woodblock print (nishiki-e); ink, color, and mica on '
##                         'paper',
##               'objectid': 207197,
##               'objectnumber': '1933.4.510',
##               'people': [{'alphasort': 'Tōshūsai, Sharaku',
##                           'birthplace': None,
##                           'culture': 'Japanese',
##                           'deathplace': None,
##                           'displaydate': 'active 1794 - 1795',
##                           'displayname': 'Tōshūsai Sharaku',
##                           'displayorder': 1,
##                           'gender': 'male',
##                           'name': 'Tōshūsai Sharaku',
##                           'personid': 28644,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': 'Edo period, 1615-1868',
##               'periodid': 248,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/17388061',
##               'provenance': None,
##               'publicationcount': 3,
##               'rank': 7,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/207197',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': 'Tôshûsai Sharaku ga',
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': None,
##               'techniqueid': None,
##               'title': 'Actor Matsumoto Kôshirô IV as Gorôbei, the Fishmonger '
##                        'from San\'ya from the Play "Katakiuchi Noriai-Banashi" '
##                        '(Kiri-za)',
##               'titlescount': 1,
##               'totalpageviews': 630,
##               'totaluniquepageviews': 517,
##               'url': 'https://www.harvardartmuseums.org/collections/object/207197',
##               'verificationlevel': 2,
##               'verificationleveldescription': 'Adequate. Object is adequately '
##                                               'described but information may '
##                                               'not be vetted',
##               'worktypes': [{'worktype': 'print', 'worktypeid': '278'}]},
##              {'accessionmethod': 'Purchase',
##               'accessionyear': 2006,
##               'accesslevel': 1,
##               'century': '21st century',
##               'classification': 'Sculpture',
##               'classificationid': 30,
##               'colorcount': 10,
##               'colors': [{'color': '#961919',
##                           'css3': '#a52a2a',
##                           'hue': 'Orange',
##                           'percent': 0.6803003003003,
##                           'spectrum': '#d75776'},
##                          {'color': '#e1e1e1',
##                           'css3': '#dcdcdc',
##                           'hue': 'Grey',
##                           'percent': 0.13597597597598,
##                           'spectrum': '#955ba5'},
##                          {'color': '#fafafa',
##                           'css3': '#fffafa',
##                           'hue': 'White',
##                           'percent': 0.042522522522523,
##                           'spectrum': '#955ba5'},
##                          {'color': '#af4b4b',
##                           'css3': '#a0522d',
##                           'hue': 'Red',
##                           'percent': 0.036336336336336,
##                           'spectrum': '#d75776'},
##                          {'color': '#afafaf',
##                           'css3': '#a9a9a9',
##                           'hue': 'Grey',
##                           'percent': 0.027927927927928,
##                           'spectrum': '#8c5fa8'},
##                          {'color': '#c86464',
##                           'css3': '#cd5c5c',
##                           'hue': 'Red',
##                           'percent': 0.023303303303303,
##                           'spectrum': '#e0626d'},
##                          {'color': '#af9696',
##                           'css3': '#bc8f8f',
##                           'hue': 'Brown',
##                           'percent': 0.015495495495495,
##                           'spectrum': '#ae5596'},
##                          {'color': '#c8c8c8',
##                           'css3': '#c0c0c0',
##                           'hue': 'Grey',
##                           'percent': 0.014954954954955,
##                           'spectrum': '#8c5fa8'},
##                          {'color': '#c87d7d',
##                           'css3': '#bc8f8f',
##                           'hue': 'Red',
##                           'percent': 0.01015015015015,
##                           'spectrum': '#cb5781'},
##                          {'color': '#967d7d',
##                           'css3': '#808080',
##                           'hue': 'Brown',
##                           'percent': 0.0052252252252252,
##                           'spectrum': '#955ba5'}],
##               'commentary': None,
##               'contact': 'am_moderncontemporary@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': '© Rosemarie Trockel / Artists Rights Society '
##                            '(ARS), New York',
##               'creditline': 'Harvard Art Museums/Busch-Reisinger Museum, '
##                             'Purchase through the generosity of Wilhelm '
##                             'Winterstein',
##               'culture': 'German',
##               'datebegin': 2006,
##               'dated': '2006',
##               'dateend': 2006,
##               'dateoffirstpageview': '2009-05-12',
##               'dateoflastpageview': '2018-10-17',
##               'department': 'Busch-Reisinger Museum',
##               'description': 'Ceramic made from a mould formed from rare meat. '
##                              'Intense, unevenly applied, red glaze maintains '
##                              'the strong allusion to blood and flesh. The '
##                              'organic forms are structured by the rectilinear '
##                              '"grid" of a central spine and "ribs", the slats '
##                              'and wooden structure of the eponymous '
##                              '"Shutter."\r\n'
##                              '\r\n',
##               'dimensions': 'sight: 80.1 x 61.7 x 4.9 cm',
##               'division': 'Modern and Contemporary Art',
##               'edition': None,
##               'exhibitioncount': 3,
##               'groupcount': 1,
##               'id': 317862,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/20380075',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 1024,
##                           'idsid': 20380075,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/20380075',
##                           'imageid': 269377,
##                           'publiccaption': None,
##                           'renditionnumber': 'DDC104121',
##                           'width': 768}],
##               'labeltext': 'In the German art scene of the 1980s, dominated by '
##                            'male painters, Cologne-based artist Rosemarie '
##                            'Trockel emerged as an oppositional figure. As she '
##                            'did then, she continues to address the body, '
##                            'sexuality, and violence. In Shutter (c), ragged '
##                            'edges and blood-red glaze allude to the object '
##                            'used to cast the piece: a slab of raw meat. The '
##                            'linear indentations, suggestive of a shutter, also '
##                            'evoke ribs and a spine. The work recalls '
##                            'traditional painting subjects, such as Dutch genre '
##                            'scenes of butchers’ stalls, while the shutter '
##                            'structure’s similarity to bones suggests the '
##                            'history of casting sculpture from the human body. '
##                            'Like her best-known work — large-scale '
##                            'machine-knitted panels — this sculpture combines '
##                            'high art traditions with craft materials. Trockel '
##                            'reinterprets the neatly ordered grid of modernist '
##                            'painting, importing its refined form into '
##                            'ceramics, usually a medium of craft. The grid '
##                            'appears as a futile attempt to tame the '
##                            'unrelenting materiality of the sculpture, rooted '
##                            'in bodily forms and tinged with the suggestion of '
##                            'violence.',
##               'lastupdate': '2018-11-08T04:22:00-0500',
##               'markscount': 1,
##               'mediacount': 0,
##               'medium': 'Stoneware with red glaze',
##               'objectid': 317862,
##               'objectnumber': '2006.236',
##               'people': [{'alphasort': 'Trockel, Rosemarie',
##                           'birthplace': 'Schwerte, Germany',
##                           'culture': 'German',
##                           'deathplace': None,
##                           'displaydate': 'born 1952',
##                           'displayname': 'Rosemarie Trockel',
##                           'displayorder': 1,
##                           'gender': 'female',
##                           'name': 'Rosemarie Trockel',
##                           'personid': 29090,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/20380075',
##               'provenance': 'Barbara Gladstone Gallery, representing the '
##                             'artist, 2006.\r\n',
##               'publicationcount': 1,
##               'rank': 8,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/317862',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': None,
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': 'Relief',
##               'techniqueid': 157,
##               'title': 'Shutter (c)',
##               'titlescount': 1,
##               'totalpageviews': 1365,
##               'totaluniquepageviews': 929,
##               'url': 'https://www.harvardartmuseums.org/collections/object/317862',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'sculpture', 'worktypeid': '317'}]},
##              {'accessionmethod': 'Gift',
##               'accessionyear': 1942,
##               'accesslevel': 1,
##               'century': '19th century',
##               'classification': 'Prints',
##               'classificationid': 23,
##               'colorcount': 8,
##               'colors': [{'color': '#c8af96',
##                           'css3': '#d2b48c',
##                           'hue': 'Brown',
##                           'percent': 0.32058997050147,
##                           'spectrum': '#e66c64'},
##                          {'color': '#323219',
##                           'css3': '#2f4f4f',
##                           'hue': 'Brown',
##                           'percent': 0.22513274336283,
##                           'spectrum': '#3db657'},
##                          {'color': '#c8c8af',
##                           'css3': '#c0c0c0',
##                           'hue': 'Green',
##                           'percent': 0.13958702064897,
##                           'spectrum': '#b55592'},
##                          {'color': '#4b4b32',
##                           'css3': '#556b2f',
##                           'hue': 'Green',
##                           'percent': 0.12271386430678,
##                           'spectrum': '#4ab851'},
##                          {'color': '#7d644b',
##                           'css3': '#696969',
##                           'hue': 'Yellow',
##                           'percent': 0.095929203539823,
##                           'spectrum': '#b25593'},
##                          {'color': '#af967d',
##                           'css3': '#bc8f8f',
##                           'hue': 'Brown',
##                           'percent': 0.050619469026549,
##                           'spectrum': '#c25687'},
##                          {'color': '#967d64',
##                           'css3': '#808080',
##                           'hue': 'Brown',
##                           'percent': 0.04188790560472,
##                           'spectrum': '#b65590'},
##                          {'color': '#e1c8c8',
##                           'css3': '#d8bfd8',
##                           'hue': 'Orange',
##                           'percent': 0.0035398230088496,
##                           'spectrum': '#c15689'}],
##               'commentary': None,
##               'contact': 'am_europeanamerican@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': None,
##               'creditline': 'Harvard Art Museums/Fogg Museum, Gift of Paul J. '
##                             'Sachs',
##               'culture': 'American',
##               'datebegin': 1888,
##               'dated': '1888',
##               'dateend': 1888,
##               'dateoffirstpageview': '2009-09-20',
##               'dateoflastpageview': '2018-10-18',
##               'department': 'Department of Prints',
##               'description': None,
##               'dimensions': 'sheet: 45.5 x 60.7 cm (17 15/16 x 23 7/8 in.)\r\n'
##                             'image: 35 x 51.8 cm (13 3/4 x 20 3/8 in.)',
##               'division': 'European and American Art',
##               'edition': None,
##               'exhibitioncount': 0,
##               'groupcount': 1,
##               'id': 256137,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/20406739',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 1929,
##                           'idsid': 20406739,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/20406739',
##                           'imageid': 267683,
##                           'publiccaption': None,
##                           'renditionnumber': 'INV159817',
##                           'width': 2550}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:10:38-0500',
##               'markscount': 5,
##               'mediacount': 0,
##               'medium': 'Etching on off white wove paper',
##               'objectid': 256137,
##               'objectnumber': 'M10128',
##               'people': [{'alphasort': 'Homer, Winslow',
##                           'birthplace': 'Boston, MA',
##                           'culture': 'American',
##                           'deathplace': 'Prouts Neck, ME',
##                           'displaydate': '1836 - 1910',
##                           'displayname': 'Winslow Homer',
##                           'displayorder': 1,
##                           'gender': 'male',
##                           'name': 'Winslow Homer',
##                           'personid': 26501,
##                           'prefix': None,
##                           'role': 'Artist'}],
##               'peoplecount': 1,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/20406739',
##               'provenance': None,
##               'publicationcount': 0,
##               'rank': 9,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/256137',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': None,
##               'standardreferencenumber': None,
##               'state': None,
##               'style': None,
##               'technique': 'Etching',
##               'techniqueid': 116,
##               'title': 'Perils of the Sea',
##               'titlescount': 1,
##               'totalpageviews': 404,
##               'totaluniquepageviews': 359,
##               'url': 'https://www.harvardartmuseums.org/collections/object/256137',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'print', 'worktypeid': '278'}]},
##              {'accessionmethod': 'Purchase',
##               'accessionyear': 2000,
##               'accesslevel': 1,
##               'century': '16th century',
##               'classification': 'Prints',
##               'classificationid': 23,
##               'colorcount': 8,
##               'colors': [{'color': '#c8c8c8',
##                           'css3': '#c0c0c0',
##                           'hue': 'Grey',
##                           'percent': 0.42640522875817,
##                           'spectrum': '#8c5fa8'},
##                          {'color': '#e1e1e1',
##                           'css3': '#dcdcdc',
##                           'hue': 'Grey',
##                           'percent': 0.24267973856209,
##                           'spectrum': '#955ba5'},
##                          {'color': '#afafaf',
##                           'css3': '#a9a9a9',
##                           'hue': 'Grey',
##                           'percent': 0.12732026143791,
##                           'spectrum': '#8c5fa8'},
##                          {'color': '#969696',
##                           'css3': '#a9a9a9',
##                           'hue': 'Grey',
##                           'percent': 0.086601307189542,
##                           'spectrum': '#8761aa'},
##                          {'color': '#7d7d7d',
##                           'css3': '#808080',
##                           'hue': 'Grey',
##                           'percent': 0.063790849673203,
##                           'spectrum': '#8362aa'},
##                          {'color': '#646464',
##                           'css3': '#696969',
##                           'hue': 'Grey',
##                           'percent': 0.038496732026144,
##                           'spectrum': '#7866ad'},
##                          {'color': '#4b4b4b',
##                           'css3': '#2f4f4f',
##                           'hue': 'Grey',
##                           'percent': 0.01359477124183,
##                           'spectrum': '#3db657'},
##                          {'color': '#323232',
##                           'css3': '#2f4f4f',
##                           'hue': 'Grey',
##                           'percent': 0.0011111111111111,
##                           'spectrum': '#2eb45d'}],
##               'commentary': None,
##               'contact': 'am_europeanamerican@harvard.edu',
##               'contextualtextcount': 0,
##               'copyright': None,
##               'creditline': 'Harvard Art Museums/Fogg Museum, '
##                             'Light-Outerbridge Collection, Richard Norton '
##                             'Memorial Fund',
##               'culture': 'Flemish',
##               'datebegin': 1561,
##               'dated': '1561',
##               'dateend': 1561,
##               'dateoffirstpageview': '2012-07-20',
##               'dateoflastpageview': '2018-10-18',
##               'department': 'Department of Prints',
##               'description': None,
##               'dimensions': 'plate: 13.2 x 19.6 cm (5 3/16 x 7 11/16 in.)',
##               'division': 'European and American Art',
##               'edition': None,
##               'exhibitioncount': 2,
##               'groupcount': 1,
##               'id': 237769,
##               'imagecount': 1,
##               'imagepermissionlevel': 0,
##               'images': [{'baseimageurl': 'https://idscache.harvardartmuseums.org/ids/view/43182614',
##                           'copyright': 'President and Fellows of Harvard '
##                                        'College',
##                           'displayorder': 1,
##                           'format': 'image/jpeg',
##                           'height': 1747,
##                           'idsid': 43182614,
##                           'iiifbaseuri': 'https://ids.lib.harvard.edu/ids/iiif/43182614',
##                           'imageid': 129601,
##                           'publiccaption': None,
##                           'renditionnumber': '44030',
##                           'width': 2550}],
##               'labeltext': None,
##               'lastupdate': '2018-11-08T04:06:56-0500',
##               'markscount': 0,
##               'mediacount': 0,
##               'medium': None,
##               'objectid': 237769,
##               'objectnumber': 'M24515',
##               'people': [{'alphasort': 'Doetecum, Joannes van',
##                           'birthplace': 'Deventer',
##                           'culture': 'Netherlandish',
##                           'deathplace': 'Haarlem',
##                           'displaydate': 'active 1554 - c. 1600',
##                           'displayname': 'Joannes van Doetecum',
##                           'displayorder': 1,
##                           'gender': 'male',
##                           'name': 'Joannes van Doetecum',
##                           'personid': 18253,
##                           'prefix': None,
##                           'role': 'Artist'},
##                          {'alphasort': 'Master of the Small Landscapes',
##                           'birthplace': None,
##                           'culture': 'Netherlandish',
##                           'deathplace': None,
##                           'displaydate': 'active c. 1560',
##                           'displayname': 'After Master of the Small Landscapes',
##                           'displayorder': 2,
##                           'gender': 'unknown',
##                           'name': 'Master of the Small Landscapes',
##                           'personid': 27477,
##                           'prefix': 'After',
##                           'role': 'Artist after'}],
##               'peoplecount': 2,
##               'period': None,
##               'periodid': None,
##               'primaryimageurl': 'https://idscache.harvardartmuseums.org/ids/view/43182614',
##               'provenance': None,
##               'publicationcount': 0,
##               'rank': 10,
##               'relatedcount': 0,
##               'seeAlso': [{'format': 'application/json',
##                            'id': 'https://iiif.harvardartmuseums.org/manifests/object/237769',
##                            'profile': 'http://iiif.io/api/presentation/2/context.json',
##                            'type': 'IIIF Manifest'}],
##               'signed': None,
##               'standardreferencenumber': 'N.H.142, Bast. 48',
##               'state': 'ii/iii',
##               'style': None,
##               'technique': 'Engraving',
##               'techniqueid': 98,
##               'title': 'Fields and a Village Road, with a Post Mill',
##               'titlescount': 2,
##               'totalpageviews': 435,
##               'totaluniquepageviews': 369,
##               'url': 'https://www.harvardartmuseums.org/collections/object/237769',
##               'verificationlevel': 3,
##               'verificationleveldescription': 'Good. Object is well described '
##                                               'and information is vetted',
##               'worktypes': [{'worktype': 'print', 'worktypeid': '278'}]}]}

That’s it. Really, we are done here. Everyone go home!

OK not really, there is still more we can lean. But you have to admit that was pretty easy. If you can identify a service that returns the data you want in structured from, web scraping becomes a pretty trivial enterprise. We’ll discuss several other scenarios and topics, but for some web scraping tasks this is really all you need to know.

Organizing and saving the data

The records we retrieved from https://www.harvardartmuseums.org/browse are arranged as a list of dictionaries. With only a little trouble we can select the fields of interest and arrange these data into a pandas DataFrame. First lets see what fields are available.

## dict_keys(['info', 'records'])
## dict_keys(['accessionyear', 'technique', 'mediacount', 'edition', 'totalpageviews', 'groupcount', 'people', 'objectnumber', 'colorcount', 'lastupdate', 'rank', 'imagecount', 'description', 'dateoflastpageview', 'dateoffirstpageview', 'primaryimageurl', 'colors', 'dated', 'contextualtextcount', 'copyright', 'period', 'accessionmethod', 'url', 'provenance', 'images', 'publicationcount', 'objectid', 'culture', 'verificationleveldescription', 'standardreferencenumber', 'worktypes', 'department', 'state', 'markscount', 'contact', 'titlescount', 'id', 'title', 'verificationlevel', 'division', 'style', 'commentary', 'relatedcount', 'datebegin', 'labeltext', 'totaluniquepageviews', 'dimensions', 'exhibitioncount', 'techniqueid', 'dateend', 'creditline', 'imagepermissionlevel', 'signed', 'periodid', 'century', 'classificationid', 'medium', 'peoplecount', 'accesslevel', 'classification', 'seeAlso'])

Next we can specify the fields we are interested in and use a dict comprehension to organize the values;

Finally we can convert the dict to a DataFrame

##    accessionyear             technique              ...                classification                        seeAlso
## 0           1927            Red-figure              ...                       Vessels  [{'id': 'https://iiif.harv...
## 1           2007    Iris digital print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 2           2007               Collage              ...                      Drawings  [{'id': 'https://iiif.harv...
## 3           2008    Dye transfer print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 4           2008  Gelatin silver print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 5           2011  Albumen silver print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 6           1933                  None              ...                        Prints  [{'id': 'https://iiif.harv...
## 7           2006                Relief              ...                     Sculpture  [{'id': 'https://iiif.harv...
## 8           1942               Etching              ...                        Prints  [{'id': 'https://iiif.harv...
## 9           2000             Engraving              ...                        Prints  [{'id': 'https://iiif.harv...
## 
## [10 rows x 61 columns]

and write the data to a file.

Iterating to retrieve all the data

Of course we don’t want just the first page of collections. How can we retrieve all of them?

Now that we know the web service works, and how to make requests in Python, we can iterate in the usual way.

For convenience we can flatten the records in each list into one long records list

As before, we can write the data to a .csv file without too much difficulty:

##     accessionyear                      technique              ...                classification                        seeAlso
## 0          1927.0                     Red-figure              ...                       Vessels  [{'id': 'https://iiif.harv...
## 1          2007.0             Iris digital print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 2          2007.0                        Collage              ...                      Drawings  [{'id': 'https://iiif.harv...
## 3          2008.0             Dye transfer print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 4          2008.0           Gelatin silver print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 5          2011.0           Albumen silver print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 6          1933.0                           None              ...                        Prints  [{'id': 'https://iiif.harv...
## 7          2006.0                         Relief              ...                     Sculpture  [{'id': 'https://iiif.harv...
## 8          1942.0                        Etching              ...                        Prints  [{'id': 'https://iiif.harv...
## 9          2000.0                      Engraving              ...                        Prints  [{'id': 'https://iiif.harv...
## 10         2002.0                           None              ...                     Paintings  [{'id': 'https://iiif.harv...
## 11         1933.0                           None              ...                        Prints  [{'id': 'https://iiif.harv...
## 12         1943.0                           None              ...                      Drawings  [{'id': 'https://iiif.harv...
## 13         1995.0                           None              ...                       Vessels  [{'id': 'https://iiif.harv...
## 14         2004.0                       Repoussé              ...                       Vessels  [{'id': 'https://iiif.harv...
## 15            NaN                     Lithograph              ...                        Prints  [{'id': 'https://iiif.harv...
## 16         1999.0            Blue-and-white ware              ...                       Vessels  [{'id': 'https://iiif.harv...
## 17         2009.0  Etching, softground etchin...              ...                        Prints  [{'id': 'https://iiif.harv...
## 18         1991.0                           None              ...                       Vessels  [{'id': 'https://iiif.harv...
## 19         1953.0                           None              ...                     Sculpture  [{'id': 'https://iiif.harv...
## 20         1978.0                           None              ...                     Sculpture  [{'id': 'https://iiif.harv...
## 21         1977.0                           None              ...                      Drawings  [{'id': 'https://iiif.harv...
## 22         1991.0                           None              ...                       Vessels  [{'id': 'https://iiif.harv...
## 23         2010.0                   Photogravure              ...                   Photographs  [{'id': 'https://iiif.harv...
## 24         2003.0           Albumen silver print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 25         2010.0                   Photogravure              ...                   Photographs  [{'id': 'https://iiif.harv...
## 26         2002.0                           None              ...                Artists' Tools  [{'id': 'https://iiif.harv...
## 27         1943.0                           None              ...                      Drawings  [{'id': 'https://iiif.harv...
## 28         1951.0                           None              ...                     Sculpture  [{'id': 'https://iiif.harv...
## 29            NaN                      Engraving              ...                        Prints  [{'id': 'https://iiif.harv...
## 30         2000.0                        Etching              ...                        Prints  [{'id': 'https://iiif.harv...
## 31         2010.0                   Photogravure              ...                   Photographs  [{'id': 'https://iiif.harv...
## 32            NaN                       Monotype              ...                        Prints  [{'id': 'https://iiif.harv...
## 33         1989.0                Photolithograph              ...                        Prints  [{'id': 'https://iiif.harv...
## 34         2010.0                   Photogravure              ...                   Photographs  [{'id': 'https://iiif.harv...
## 35         1924.0         Cast, lost-wax process              ...                       Vessels  [{'id': 'https://iiif.harv...
## 36         1985.0                           None              ...                        Prints  [{'id': 'https://iiif.harv...
## 37         2005.0            Chiaroscuro woodcut              ...                        Prints  [{'id': 'https://iiif.harv...
## 38         1991.0                           None              ...                       Vessels  [{'id': 'https://iiif.harv...
## 39         1940.0            Chiaroscuro woodcut              ...                        Prints  [{'id': 'https://iiif.harv...
## 40         1985.0                           None              ...                   Calligraphy  [{'id': 'https://iiif.harv...
## 41         2006.0                           None              ...                     Paintings  [{'id': 'https://iiif.harv...
## 42         2004.0                           None              ...                      Drawings  [{'id': 'https://iiif.harv...
## 43         1996.0                           None              ...                         Boxes  [{'id': 'https://iiif.harv...
## 44         2008.0                           None              ...                     Sculpture  [{'id': 'https://iiif.harv...
## 45         1906.0                           None              ...                     Paintings  [{'id': 'https://iiif.harv...
## 46         1936.0                           None              ...                        Albums  [{'id': 'https://iiif.harv...
## 47         2007.0             Iris digital print              ...                   Photographs  [{'id': 'https://iiif.harv...
## 48            NaN                  Daguerreotype              ...                   Photographs  [{'id': 'https://iiif.harv...
## 49         1943.0                           None              ...                     Sculpture  [{'id': 'https://iiif.harv...
## 
## [50 rows x 61 columns]

Exercise: Retrieve exhibits data

In this exercise you will retrieve information about the art exhibitions at Harvard Art Museums from https://www.harvardartmuseums.org/visit/exhibitions

  1. Using a web browser (Firefox or Chrome recommended) inspect the page at https://www.harvardartmuseums.org/visit/exhibitions. Examine the network traffic as you interact with the page. Try to find where the data displayed on that page comes from.
  2. Make a get request in Python to retrieve the data from the URL identified in step1.
  3. Write a loop or list comprehension in Python to retrieve data for the first 5 pages of exhibitions data.
  4. Bonus (optional): Arrange the data you retrieved into dict of lists. Convert it to a pandas DataFrame and save it to a .csv file.

Parse html if you have to

As we’ve seen, you can often inspect network traffic or other sources to locate the source of the data you are interested in and the API used to retrieve it. You should always start by looking for these shortcuts and using them where possible. If you are really lucky, you’ll find a shortcut that returns the data as JSON or XML. If you are not quite so lucky, you will have to parse HTML to retrieve the information you need.

For example, when I inspected the network traffic while interacting with https://www.harvardartmuseums.org/visit/calendar I didn’t see any requests that returned JSON data. The best we can do appears to be https://www.harvardartmuseums.org/visit/calendar?date=, which unfortunately returns HTML.

Retrieving HTML

The first step is the same as before: we make at GET request.

## 'https://www.harvardartmuseums.org/visit/calendar'

As before we can check the headers to see what type of content we received in response to our request.

Parsing HTML using the lxml library

Like JSON, HTML is structured; unlike JSON it is designed to be rendered into a human-readable page rather than simply to store and exchange data in a computer-readable format. Consequently, parsing HTML and extracting information from it is somewhat more difficult than parsing JSON.

While JSON parsing is built into the Python requests library, parsing HTML requires a separate library. I recommend using the HTML parser from the lxml library; others prefer an alternative called BeautyfulSoup.

Using xpath to extract content from HTML

XPath is a tool for identifying particular elements withing a HTML document. The developer tools built into modern web browsers make it easy to generate XPaths that can used to identify the elements of a web page that we wish to extract.

We can open the html document we retrieved and inspect it using our web browser.

Once we identify the element containing the information of interest we can use our web browser to copy the XPath that uniquely identifies that element.

Next we can use python to extract the element of interest:

Once again we can use a web browser to inspect the HTML we’re currently working with, and to figure out what we want to extract from it. Let’s look at the first element in our events list.

As before we can use our browser to find the xpath of the elements we want.

(Note that the html.open_in_browser function adds enclosing html and body tags in order to create a complete web page for viewing. This requires that we adjust the xpath accordingly.)

By repeating this process for each element we want, we can build a list of the xpaths to those elements.

Finally, we can iterate over the elements we want and extract them.

## {'date': 'Thursday, November 1, 2018',
##  'figcaption': '1958 D. A. Flentrop organ, Adolphus Busch Hall, Harvard '
##                'University.',
##  'localtion1': '29 Kirkland Street',
##  'location2': 'Cambridge',
##  'time': '12:15pm - 12:45pm',
##  'title': 'Midday Organ Recital: Beth Elswick'}

Iterating to retrieve content from a list of HTML elements

So far we’ve retrieved information only for the first event. To retrieve data for all the events listed on the page we need to iterate over the events. If we are very lucky, each event will have exactly the same information structured in exactly the same way and we can simply extend the code we wrote above to iterate over the events list.

Unfortunately not all these elements are available for every event, so we need to take care to handle the case where one or more of these elements is not available. We can do that by defining a function that tries to retrieve a value and returns an empty string if it fails.

Armed with this function we can iterate over the list of events and extract the available information for each one.

For convenience we can arrange these values in a pandas DataFrame and save them as .csv files, just as we did with our exhibitions data earlier.

##                        figcaption                          date    ...              localtion1  location2
## 0   1958 D. A. Flentrop organ,...    Thursday, November 1, 2018    ...      29 Kirkland Street  Cambridge
## 1   Rhyton forepart in the for...      Friday, November 2, 2018    ...      224 Western Avenue    Allston
## 2                                      Friday, November 2, 2018    ...        32 Quincy Street  Cambridge
## 3   Deer head rhyton depicting...    Saturday, November 3, 2018    ...        32 Quincy Street  Cambridge
## 4   Donkey head kantharos (dri...    Saturday, November 3, 2018    ...        32 Quincy Street  Cambridge
## 5   Octagonal cup with the for...    Saturday, November 3, 2018    ...        32 Quincy Street  Cambridge
## 6                                    Saturday, November 3, 2018    ...        32 Quincy Street  Cambridge
## 7                                    Saturday, November 3, 2018    ...        32 Quincy Street  Cambridge
## 8                                      Sunday, November 4, 2018    ...        32 Quincy Street  Cambridge
## 9                                      Sunday, November 4, 2018    ...        32 Quincy Street  Cambridge
## 10                                    Tuesday, November 6, 2018    ...        32 Quincy Street  Cambridge
## 11                                    Tuesday, November 6, 2018    ...        32 Quincy Street  Cambridge
## 12  Donkey head kantharos (dri...   Wednesday, November 7, 2018    ...        32 Quincy Street  Cambridge
## 13                   © Nic Lehoux   Wednesday, November 7, 2018    ...        32 Quincy Street  Cambridge
## 14       Corinne Wasmuht, German,   Wednesday, November 7, 2018    ...        32 Quincy Street  Cambridge
## 15  1958 D. A. Flentrop organ,...    Thursday, November 8, 2018    ...      29 Kirkland Street  Cambridge
## 16    Théodore Géricault, French,    Thursday, November 8, 2018    ...        32 Quincy Street  Cambridge
## 17                                     Friday, November 9, 2018    ...        32 Quincy Street  Cambridge
## 18                                  Saturday, November 10, 2018    ...        32 Quincy Street  Cambridge
## 19                                  Saturday, November 10, 2018    ...        32 Quincy Street  Cambridge
## 20                                    Sunday, November 11, 2018    ...        32 Quincy Street  Cambridge
## 21                                    Sunday, November 11, 2018    ...        32 Quincy Street  Cambridge
## 22     Gordon W. Gahan, American,     Monday, November 12, 2018    ...        32 Quincy Street  Cambridge
## 23   Charles Bird King, American,    Tuesday, November 13, 2018    ...        32 Quincy Street  Cambridge
## 24                                 Wednesday, November 14, 2018    ...        32 Quincy Street  Cambridge
## 25  Donkey head kantharos (dri...  Wednesday, November 14, 2018    ...        32 Quincy Street  Cambridge
## 26  Ram head mug depicting sym...  Wednesday, November 14, 2018    ...        32 Quincy Street  Cambridge
## 27                                 Wednesday, November 14, 2018    ...        32 Quincy Street  Cambridge
## 28  1958 D. A. Flentrop organ,...   Thursday, November 15, 2018    ...      29 Kirkland Street  Cambridge
## 29                                  Thursday, November 15, 2018    ...        32 Quincy Street  Cambridge
## 30  Timothy H. O’Sullivan, Ame...     Friday, November 16, 2018    ...        32 Quincy Street  Cambridge
## 31                                    Friday, November 16, 2018    ...        32 Quincy Street  Cambridge
## 32  Bell krater depicting a sy...     Friday, November 16, 2018    ...      224 Western Avenue    Allston
## 33    Théodore Géricault, French,   Saturday, November 17, 2018    ...        32 Quincy Street  Cambridge
## 34                                  Saturday, November 17, 2018    ...        32 Quincy Street  Cambridge
## 35                                  Saturday, November 17, 2018    ...        32 Quincy Street  Cambridge
## 36                                    Sunday, November 18, 2018    ...        32 Quincy Street  Cambridge
## 37                                    Sunday, November 18, 2018    ...        32 Quincy Street  Cambridge
## 38  Eagle head mug. Attributed...  Wednesday, November 21, 2018    ...        32 Quincy Street  Cambridge
## 39         Harry Annas, American,   Thursday, November 22, 2018    ...        32 Quincy Street  Cambridge
## 40                                   Tuesday, November 27, 2018    ...        32 Quincy Street  Cambridge
## 41           Photo: Danny Hoshino    Tuesday, November 27, 2018    ...        32 Quincy Street  Cambridge
## 42  Octagonal cup with the for...  Wednesday, November 28, 2018    ...        32 Quincy Street  Cambridge
## 43  Rhyton with the forepart o...  Wednesday, November 28, 2018    ...        32 Quincy Street  Cambridge
## 44  1958 D. A. Flentrop organ,...   Thursday, November 29, 2018    ...      29 Kirkland Street  Cambridge
## 45                                    Friday, November 30, 2018    ...        32 Quincy Street  Cambridge
## 46                                    Friday, November 30, 2018    ...        32 Quincy Street  Cambridge
## 
## [47 rows x 6 columns]

Exercise: parsing HTML

In this exercise you will retrieve information about the physical layout of the Harvard Art Museums. The web page at https://www.harvardartmuseums.org/visit/floor-plan contains this information in HTML from.

  1. Using a web browser (Firefox or Chrome recommended) inspect the page at https://www.harvardartmuseums.org/visit/floor-plan. Copy the XPath to the element containing the list of level information. (HINT: the element if interest is a ul, i.e., unordered list.)
  2. Make a get request in Python to retrieve the web page at https://www.harvardartmuseums.org/visit/floor-plan. Extract the content from your request object and parse it using html.fromstring from the lxml library.
  3. Use your web browser to find the XPaths to the facilities housed on level one. Use Python to extract the text from those Xpaths.
  4. Bonus (optional): Write a loop or list comprehension in Python to retrieve data for all the levels.

Use Scrapy for large or complicated projects

Scraping websites using the requests library to make GET and POST requests, and the lxml library to process HTML is a good way to learn basic web scraping techniques. It is a good choice for small to medium size projects. For very large or complicated scraping tasks the scrapy library offers a number of conveniences, including asynchronously retrieval, session management, convenient methods for extracting and storing values, and more. More information about scrapy can be found at https://doc.scrapy.org.

Use a browser driver as a last resort

It is sometimes necessary (or sometimes just easier) to use a web browser as an intermediary rather than communicating directly with a web service. This method has the advantage of being about to use the javascript engine and session management features of a web browser; the main disadvantage is that it is slower and tends to be more fragile than using requests or scrapy to make requests directly from python. For small scraping projects involving complicated sites with CAPTHAs or lots of complicated javascript using a browser driver can be a good option. More information is available at https://www.seleniumhq.org/docs/03_webdriver.jsp.